package com.northpool.operator.cicd.oshi;

import cn.hutool.system.oshi.OshiUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.northpool.operator.annotation.OperatorInfo;
import com.northpool.operator.annotation.OutputParam;
import com.northpool.operator.annotation.OutputParams;
import com.northpool.operator.common.algorithm.OperatorTestBuild;
import com.northpool.operator.common.algorithm.TestParamBuilder;
import com.northpool.operator.param.ParamTool;
import com.northpool.operator.utils.StpOperatorHelper;
import oshi.hardware.GlobalMemory;

@OperatorInfo(
        ref = "SystemInfo",
        name = "系统信息",
        version = "memory",
        description = "服务器内存信息统计"
)
@OutputParams({
        @OutputParam(ref = "result", name = "内存信息")
})
public class MemInfoOperator extends StpOperatorHelper {
    public MemInfoOperator() {
    }

    public static void main(String[] args) {
        OperatorTestBuild.execute(MemInfoOperator.class, TestParamBuilder.aBuilder()
                .build());
    }

    @Override
    public void execute(ParamTool paramTool) throws Exception {
        GlobalMemory memory = OshiUtil.getMemory();
        String jsonString = JSONObject.toJSONString(memory, SerializerFeature.PrettyFormat);
        this.result("result", jsonString);
    }
}
